package com.etl.dataflow.executor.connectivity;


import com.etl.dataflow.common.exception.EtlException;
import com.etl.dataflow.executor.connectivity.DbType;
import com.etl.dataflow.executor.connectivity.TypedJdbcProperties;
import com.etl.dataflow.executor.connectivity.connector.Connector;
import com.etl.dataflow.executor.connectivity.connector.MySqlConnector;
import com.etl.dataflow.executor.connectivity.connector.OracleConnector;

import java.util.HashMap;
import java.util.Map;

/**
 * 数据库连接器工厂
 *
 * @author dx
 */
public class ConnectorFactory {

    private static final Map<DbType, Connector> connectorMap = new HashMap<>(4);

    static {
        connectorMap.put(DbType.MYSQL, new MySqlConnector());
        connectorMap.put(DbType.ORACLE, new OracleConnector());
    }

    public static Connector getConnector(TypedJdbcProperties typedJdbcProperties) {
        if (!connectorMap.containsKey(typedJdbcProperties.getDbType())) {
            throw new EtlException("尚不支持此类型的数据库: " + typedJdbcProperties.getDbType());
        }
        return connectorMap.get(typedJdbcProperties.getDbType());
    }
}
